<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/header.jsp" %>
<div class="row">
	<div class="col-xs-12">
		<div class="table-header">
			子参数列表
		</div>
		<div>
			<form>
				<table id="subListTab" class="table table-striped table-bordered table-hover">
					<thead>
						<tr>
							<th class="center">序号</th>	
							<th class="center">参数类型</th>	
							<th class="center">参数名称</th>	
							<th class="center">所属机构</th>	
							<th class="center">参数主键</th>	
							<th class="center">操作</th>			
						</tr>
					</thead>
					<tbody>
						<c:forEach items="${subParamList}" var="a" varStatus="sub">
							<tr>
							   	<td>${sub.index + 1}</td>					   	
								<td>${a.paramType}</td>
								<td>${a.remark}</td>
								<td>
								<hw:orgName orgId="${a.orgId}"/>
								</td>	
								<td>${a.paramKey}</td>		
								<td>
								<div class="hidden-sm hidden-xs action-buttons">
									<a class="green" href="javascript:void(0)" onclick="showDetail('${a.paramType}','${a.orgId}','${a.paramKey}')" title="修改">
										<i class="ace-icon fa fa-pencil bigger-130"></i>
									</a>
									<a class="red" href="javascript:void(0)" onclick="removeParam('${a.paramType}','${a.orgId}','${a.paramKey}')" data-toggle="tooltip" title="删除">
										<i class="ace-icon fa fa-trash-o bigger-130"></i>
									</a>
								</div>
								</td>		
							</tr>	
							</c:forEach>					
					</tbody>
				</table>
			</form>
		</div>
	</div>
</div>

<!-- page specific plugin scripts -->
<script type="text/javascript">
function remove(paramType,orgId,paramKey) {
	var flag = confirm("确认删除吗？");
	if(flag){
	enabledAll();
	var params={"paramType":paramType,"orgId":orgId,"paramKey":paramKey};
	$.ajax({
		async : false,
		url: "${ctx}/parameter/delete.do",
		type:"post",
		data: $.param(params),
		dataType:"json",
		success: function(ret){	
			if (ret[0] == "ok") {
				alert(ret[1]);
				$("#paraDetailIframe").dialog("close");
				showSubList(paramType);
			} else {
				alert(ret[1]);
				disabledAll();
			}				
		},
		error: function(ret){
			alert(ret.responseText);
			disabledAll();
		}
	});	
	}
}

function showDetail(paramType,orgId,paramKey){
	var params={"paramType":paramType,"orgId":orgId,"paramKey":paramKey};
	$("#paraDetailIframe").load("${ctx}/parameter/detail.do",params);	
	$('#paraDetailIframe').dialog('open');
	
}
	var oTableSub;		
	var scripts = [null, null];
	$('.page-content-area').ace_ajax('loadScripts', scripts, function() {

		oTableSub = $("#subListTab").dataTable({
		    "bAutoWidth": false,	
		    "bDestroy":true,
			"aoColumnDefs": [{"bSortable": true, "aTargets": [ 0]} 
							/* ,{"bSearchable": false, "bVisible": false, "aTargets": [4]}
							,{"bSearchable": false, "bVisible": false, "aTargets": [5]} */
			],
			"oLanguage":oLanguage,
			"fnInitComplete": function(param){
				$("#subListTab_filter").append("<button class=\"btn btn-sm btn-info btn-right\" type=\"button\" id=\"btnAdd\">"+
						"<i class=\"ace-icon fa fa-plus-square bigger-110\"></i>"+
							"新增"+
						"</button>");
			}
			
		});
		
		 $("#btnAdd").click(function(){
			 	var params = {paramType : "${paramType}"};
				$("#paraDetailIframe").load("${ctx}/parameter/toAdd.do",$.param(params),function(){
					$('#paraDetailIframe').dialog('open');
				});	
				
		 });
	});	
		//override dialog's title function to allow for HTML titles
		$.widget("ui.dialog", $.extend({}, $.ui.dialog.prototype, {
			_title: function(title) {
				var $title = this.options.title || '&nbsp;'
				if( ("title_html" in this.options) && this.options.title_html == true )
					title.html($title);
				else title.text($title);
			}
		}));
		
		
		//参数详细信息
		$('#paraDetailIframe').dialog({
			hide:true,
			autoOpen:false,
			width: 800,
			height:600,
			modal:true,
			title: "<div class='widget-header'><h4 class='smaller'><i class='ace-icon fa fa-cog green'></i>&nbsp; 参数管理</h4></div>",
			title_html: true,			
			buttons: [
				{
					id: "btnPModify",
					html: "<i class='ace-icon fa fa-pencil-square-o bigger-110'></i>&nbsp; 修改",
					"class" : "btn btn-primary btn-minier",
					click: function() {
						modify();
					}
				},
				{
					id: "btnPSave",
					html: "<i class='ace-icon fa fa-floppy-o bigger-110'></i>&nbsp; 保存",
					"class" : "btn btn-success btn-minier",
					click: function() {
						save();
					}
				},
				{
					id: "btnPCancle",
					html: "<i class='ace-icon fa fa-undo bigger-110'></i>&nbsp; 取消",
					"class" : "btn btn-warning btn-minier",
					click: function() {
						cancle();
					}
				},												
				{
					id: "btnPClose",
					html: "<i class='ace-icon fa fa-times bigger-110'></i>&nbsp; 关闭",
					"class" : "btn btn-minier",
					click: function() {
						$(this).dialog("close");
					}
				}				
			]				
		});
		
		 $('#subListTab').on('click', 'tbody tr' , function(){
			var active_class = 'success';
			var $row = $(this).closest('tr');	
			if ($row.hasClass(active_class) == false) {
				oTableSub.$('tr.' + active_class).removeClass(active_class);
				$row.addClass(active_class);				
			}
		 });
		
		 
		 
	/* $('#subListTab').on('dblclick', 'tbody tr' , function(){
		var aData = oTableSub.fnGetData(this); 
		if (aData == null) {
			return;
		} 
		showDetail(aData[1],aData[5],aData[3]);
	}); */
	
	function remove() {
		enabledAll("detailForm");
		if(confirm("确认删除吗？")){
		$.ajax({
			async : false,
			url: "${ctx}/parameter/delete.do",
			type:"post",
			data: $("#detailForm").serialize(),
			dataType:"json",
			success: function(ret){	
				if (ret[0] == "ok") {
					alert(ret[1]);
					$("#paraDetailIframe").dialog("close");
					showSubList("${paramInfo.paramType}");
				} else {
					alert(ret[1]);
					disabledAll("detailForm");
				}				
			},
			error: function(ret){
				alert(ret.responseText);
				disabledAll("detailForm");
			}
		});	
		}
		}
	
	
	function removeParam(paramType,orgId,paramKey){
		removeItem(paramType,orgId,paramKey,function(){
			showSubList(paramType);
		});
	}


	function removeItem(paramType,orgId,paramKey,callback){
		if(confirm("确定删除该项吗?")){
			$.post("${ctx}/parameter/delete.do",{"paramType":paramType,"orgId":orgId,"paramKey":paramKey},function(result){
				if(result[0] == "ok"){
					alert("删除成功！");
					callback();
				}else{
					alert(result[1]);
				}
			})
		}
	}
	
	
	
</script>